package com.example.personalblog.controller;

import com.example.personalblog.service.ArticleService;
import com.example.personalblog.service.ClassifyService;
import com.example.personalblog.vo.DisplayArticle;
import com.example.personalblog.vo.DisplayClassify;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class typesController {

    @Autowired
    ClassifyService classifyService;

    @Autowired
    ArticleService articleService;

    @GetMapping("/types/{id}/{pageNum}")
    public String getTypes(@PathVariable int pageNum,
                           @PathVariable int id,
                           Model model){
        List<DisplayClassify> classifyList = classifyService.findAllClassify();
        PageInfo<DisplayArticle> pageInfo = null;
        if (id ==0){
            pageInfo =  articleService.findAllArticle(pageNum, "");
        } else {
            pageInfo = articleService.findByClid(pageNum, id);

        }


        model.addAttribute("classifyList", classifyList);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("id", id);

        return "/types";

    }

}
